package com.wx.collection;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 集合类测试
 *
 * @author wangxun
 * @date 2023/04/19
 */
public class CollectionTest {
    @Test
    public void subListTest(){
        List<String> sourceList = new ArrayList<String>() {{
            add("H");
            add("O");
            add("L");
            add("L");
            add("I");
            add("S");
        }};

        List<String> subList = sourceList.subList(0, 3);
        // list 拷贝
        List<String> collect = subList.stream().skip(0).limit(2).collect(Collectors.toList());
        System.out.println(collect);

        subList.add(0,"W");
        System.out.println("subList:"+subList);
        System.out.println("sourceList:"+sourceList);
        System.out.println("collect:"+collect);
    }

}
